package com.ruoyi.cms.service.impl;

import com.ruoyi.cms.domain.ShortCollection;
import com.ruoyi.cms.mapper.ShortCollectionMapper;
import com.ruoyi.cms.service.IShortCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * 短视频收藏Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-24
 */
@Service
public class ShortCollectionServiceImpl implements IShortCollectionService {

    @Autowired
    private ShortCollectionMapper shortCollectionMapper;

    /**
     * 查询短视频收藏列表
     *
     * @param shortCollection 短视频收藏
     * @return 短视频收藏集合
     */
    @Override
    public List<ShortCollection> selectShortCollectionList(ShortCollection shortCollection) {
        return shortCollectionMapper.selectShortCollectionList(shortCollection);
    }

    /**
     * 新增短视频收藏
     *
     * @param shortCollection 短视频收藏
     * @return 结果
     */
    @Override
    public int insertShortCollection(ShortCollection shortCollection) {
        shortCollection.setCreateTime(new Date());
        return shortCollectionMapper.insertShortCollection(shortCollection);
    }

    /**
     * 取消收藏
     *
     * @param memberId 会员ID
     * @param shortId 短视频ID
     * @return 结果
     */
    @Override
    public int cancelCollection(Long memberId, Long shortId) {
        ShortCollection shortCollection = new ShortCollection();
        shortCollection.setMemberId(memberId);
        shortCollection.setShortId(shortId);
        return shortCollectionMapper.deleteShortCollection(shortCollection);
    }

    /**
     * 检查是否已收藏
     *
     * @param memberId 会员ID
     * @param shortId 短视频ID
     * @return 是否已收藏
     */
    @Override
    public boolean checkCollected(Long memberId, Long shortId) {
        int count = shortCollectionMapper.checkCollectionExists(memberId, shortId);
        return count > 0;
    }
}
